package com.sywb.chuangyebao.widget;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

import org.bining.footstone.log.Logger;

public class SuperViewPager extends ViewPager {

    private boolean isShowMall;
    private boolean isIntercept;
    private float downX;
    private float downY;
    private long downTime;

    public SuperViewPager(@NonNull Context context) {
        super(context);
    }

    public SuperViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        if (isShowMall) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    downX = event.getX();
                    downY = event.getY();
                    downTime = System.currentTimeMillis();
                    Logger.e("getHeight():" + getHeight() + " downX：" + downX + " downY：" + downY);
                    if (downY < (getHeight() / 3)) {
                        isIntercept = true;
                    } else {
                        isIntercept = false;
                    }
                    break;
                case MotionEvent.ACTION_UP:
                    break;
                case MotionEvent.ACTION_MOVE:
                    long moveTime = System.currentTimeMillis();
                    float moveX = event.getX();
                    float moveY = event.getY();
                    Logger.e("getHeight():" + getHeight() + " moveX：" + moveX + " moveY：" + moveY);
                    if (isIntercept) {
                        return false;
                    }
                    break;
            }
        }
        return super.onInterceptTouchEvent(event);
    }

    public void setShowMall(boolean showMall) {
        isShowMall = showMall;
    }
}
